<?php
namespace App\Http\Controllers\Web\Member\Seller;


use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;
class IndexController extends BaseController
{
    protected $api_url = [
        'shop_index' => ['get', 'seller/index'],
        'index' => ['get', 'seller/orders'],
        'product'=>['get', 'seller/product/count'],
        'article'=>['get', 'article'],
        'index_express_company' => ['get', 'seller/express_company'],
        'items_count' => ['get', 'seller/items/items_count'],
        'seller_index' => ['get', 'seller/orders/seller_index'],
        'showusercompany' => ['get', 'seller/companymaterial/%d/showusercompany'],

    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;

    }


    /**
     * 卖家中心首页
     */
    public function index()
    {
        //公司信息读取
        $ret = http_web($this->api_url['showusercompany'],[session('user_id')])->send();

        if($ret['data']['data']['identification_type'] != 2 or empty($ret['data']['data']['company'])){
            return redirect('/member/user/company');
        }

        $ret = http_web($this->api_url['shop_index'],[session('user_id')])->send();
        if(empty($ret['data']['sp_status'])){
            return redirect('/member/user/safe')->withErrors('店铺已被关闭，请联系在线客服！');
        }
        //最新订单
        $params = [
            'searchJoin' => 'and',
            'with' => 'orderProducts;shop;items_products;items_information',
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];
        $order_item= http_web($this->api_url['seller_index'])->send($params);

        $order_item =  $order_item['data'];
        foreach($order_item as $k=>$v){
            if(!empty($v['items_information'])){
                $order_item[$k]['items_information']['quote_contain']=\GuzzleHttp\json_decode($v['items_information']['quote_contain'],true);
            }
        }
        $ret['data']['order']=$order_item;

         //商品数量
         $product = http_web($this->api_url['product'])->send();
        $ret['data']['sale']=$product['data'];

        $article = http_web($this->api_url['article'])->send();
        $ret['data']['article']=$article['data'];

        $items_count = http_web($this->api_url['items_count'])->send();
        $ret['data']['items_count']=$items_count['data'];


        $express_company = http_web($this->api_url['index_express_company'])->send(['type' => 'kv']);

        return view('web.user.member.index',['data'=>$ret['data'], 'express_company' => $express_company['data']]);

    }






}